<template>
	<view class="userinfo-container">
		<!-- 头像昵称区域 -->
		<view class="header-box">
			<image class="headimg" :src="userinfo.avatarUrl" ></image>
			<view class="nickname">{{userinfo.nickName}}</view>
		</view>
		
		<!-- 面板区域 -->
		<view class="panel-container">
			
			<!-- 第一个面板 -->
			<view class="panel-one">
				<view class="panel-one-body">
					<view class="panel-item">
						<text>2</text>
						<text>收藏的店铺</text>
					</view>
					<view class="panel-item">
						<text>9</text>
						<text>收藏的商品</text>
					</view>
					<view class="panel-item">
						<text>6</text>
						<text>关注的商品</text>
					</view>
					<view class="panel-item">
						<text>99</text>
						<text>我的足迹</text>
					</view>
				</view>
			</view>
			
			<!-- 第二个面板 -->
			<view class="panel-two">
				<view class="panel-two-title">
					我的订单
				</view>
				<view class="panel-two-body">
					<view class="panel-item">
						<image class="item-img" src="../../static/qbdd.png" ></image>
						<text>全部订单</text>
					</view>
					<view class="panel-item">
						<image class="item-img" src="../../static/dfk.png" ></image>
						<text>待付款</text>
					</view>
					<view class="panel-item">
						<image class="item-img" src="../../static/dsh.png" ></image>
						<text>待收货</text>
					</view>
					<view class="panel-item">
						<image class="item-img" src="../../static/tkth.png" ></image>
						<text>退款/退货</text>
					</view>
					
				</view>
			</view>
			
			
			
			<!-- 第三个面板 -->
			<view class="panel-three">
				<view class="panel-body-item">
					<text>收货地址</text>
					<uni-icons type="right"></uni-icons>
				</view>
				<view class="panel-body-item">
					<text>联系客服</text>
					<uni-icons type="right"></uni-icons>
				</view>
				<view class="panel-body-item" @click="logout">
					<text>退出登录</text>
					<uni-icons type="right"></uni-icons>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	export default {
		name:"my-userinfo",
		data() {
			return {
				
			};
		},
		methods:{
			...mapMutations('m_user',['updateUserInfo','updateToken','updateAddress']),
			
			//退出登录
			async logout(){
				const [err,succ] = await uni.showModal({
					title:'提示',
					content:'确认退出登录吗？'
				}).catch(err => err)
				// console.log('ui:',err,succ);
				if(succ && succ.confirm){
					// 用户确认了退出登录的操作
					// 需要清空 vuex 中的 userinfo、token 和 address
					this.updateAddress({})
					this.updateToken('')
					this.updateUserInfo({})
				}
			}
		},
		computed:{
			...mapState('m_user',['userinfo'])
		}
	}
</script>

<style lang="scss">
	.userinfo-container{
		height: 100%;
		background-color: #f4f4f4;
		.header-box{
			height: 400rpx;
			background-color: #c00000;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			.headimg{
				width: 90px;
				height: 90px;
				border-radius: 50px;
				border: 2px solid white;
				box-shadow: 0 1px 5px black;
			}
			.nickname{
				font-size: 16px;
				color: white;
				font-weight: bold;
				margin-top: 10px;
			}
		}
		
		
		.panel-container{
			padding: 0 10px;
			position: relative;
			top: -10px;
			
			// 第一个面板
			.panel-one{
				background-color: white;
				border-radius: 5px;
				margin-bottom: 10px;
				.panel-one-body{
					display: flex;
					justify-content: space-around;
					font-size: 14px;
					.panel-item{
						display: flex;
						flex-direction: column;
						justify-content: space-around;
						align-items: center;
						padding: 10px 0;
					}
				}
			}
			// 第二个面板
			.panel-two{
				background-color: white;
				border-radius: 5px;
				margin-bottom: 10px;
				.panel-two-title{
					font-size: 16px;
					padding-left: 10px;
					line-height: 40px;
					border-bottom: 1px solid #f4f4f4;
				}
				.panel-two-body{
					display: flex;
					justify-content: space-around;
					align-items: center;
					font-size: 13px;
					padding: 10px 0;
					.panel-item{
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: space-around;
						.item-img{
							width: 35px;
							height: 35px;
						}
					}
				}
			}
			
			//第三个面板
			.panel-three{
				background-color: white;
				border-radius: 5px;
				margin-bottom: 10px;
				.panel-body-item{
					display: flex;
					justify-content: space-between;
					height: 40px;
					align-items: center;
					font-size: 15px;
					padding: 0 10px;
				}
			}
			
		}
	}
</style>